package com.glory.good_dark.activity;

import android.app.Activity;
import android.content.Context;
import android.widget.TextView;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.glory.good_dark.application.App;
import com.glory.good_dark.application.BaseActivity;
import com.glory.good_dark.entity.EqpStateEntity;
import com.glory.good_dark.entity.LotIDInfoEntity;
import com.glory.good_dark.entity.response.BaseEntity;
import com.glory.good_dark.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_TextCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;


/**
 * @author yi.zhang
 * @date 2019/6/17
 * @desc 更换设备处理界面
 */
public abstract class BaseProjectActivity extends BaseActivity {

    protected FreeUI_GeneralFragmentDialog dialogs;

    /**
     * EQP更换成功方法
     */
    protected abstract void EQPReplaceSuccess(int tag,String content);

    protected void initRecyclerView(RecyclerView recyclerView, Context context){
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.addItemDecoration(new DividerItemDecoration(context, 1));
    }

    protected void initGridRecyclerView(RecyclerView recyclerView,Context context,int spanCount){
        recyclerView.setLayoutManager(new GridLayoutManager(context,spanCount));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }
    //LotIDInfoEntity//EqpStateEntity
    protected void getEqpState(TextView textView, Activity context){
        FreeUI_EntityCallBack<BaseEntity<LotIDInfoEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<LotIDInfoEntity>>
                (new TypeToken<BaseEntity<LotIDInfoEntity>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess
                    (final Response<BaseEntity<LotIDInfoEntity>> response) {
                if (response.body().isSuccess(context,getSupportFragmentManager(),true)) {
                    textView.setText(response.body().getData().getBody().getEQP_RUN_STATE());
                }
            }

            @Override
            public void onError
                    (Response<BaseEntity<LotIDInfoEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "PDAGetEqpLotidList");//PDAGetEqpLotidList//PDAGetEqpInfo
            }
        };

        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("EQP_ID", App.EQPID);
        NetUtils.requestPostNet(App.WEB_URL + "/api/PDA", this, callBack, "PDAGetEqpLotidList", jsonObject);//PDAGetEqpLotidList//PDAGetEqpInfo
    }

    protected void showSpanDialog(int tag,String message){
        dialogs = FreeApi_DialogUtils.getScanDialog(this, message, s -> {
            EQPReplaceSuccess(tag,s);
            dialogs.dismiss();
        });
        dialogs.show(getSupportFragmentManager(), "WEB_URL_DIALOG");
    }

}
